const app = getApp();
export const getCoupon = ({
  detail: {
    errcode,
    msg,
    send_coupon_result
  }
}) => new Promise((resolve, reject) => {
  let title = '';
  if (errcode === 'OK') {
    const code = send_coupon_result[0].code;
    if (code === 'SUCCESS') {
      return resolve();
    } else if (code === 'DUPREQUEST') {
      title = '卡券已领取成功，请勿重复领取';
    } else {
      title = send_coupon_result[0].message;
    }
  } else {
    title = msg;
  }
  xhs.showToast({
    icon: 'none',
    title
  });
  reject();
});
export const getCouponParams = data => new Promise(resolve => {
  app.$getData('/user/coupon/get-mch-coupon-params', data).then(data => {
    if (data.errCode == '0') {
      resolve(data);
    } else if (data.errCode == '210042') {
      return;
    } else {
      xhs.showToast({
        title: data.errInfo,
        icon: 'none'
      });
    }
  });
});